<template>
  <div class="app-container pr">
    <div class="page-left">
      <Organ :get-data="selectNode" :info="info" />
    </div>
    <div class="page-right fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl">
          <el-input v-model="filter.nickname" placeholder="用户名称" size="small" clearable />
        </el-form-item>
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button type="primary" size="small" @click="getList()">查 询</el-button>
          <el-button :disabled="filter.parent_id !== '0' ? true : false" type="primary" size="small" @click="handleAdd()">新 增</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="app.loading" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
        <el-table-column label="序号" align="center" width="56px" fixed="left">
          <template slot-scope="{$index}">
            {{ $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="用户名" min-width="120px" prop="nickname" fixed="left" />
        <el-table-column label="手机号" align="center" width="120px" prop="phone" />
        <el-table-column label="部门" min-width="150px" prop="dept_name" />
        <el-table-column label="职位" min-width="150px" prop="role_name" />
        <el-table-column label="邮箱" min-width="200px" prop="email" />
        <el-table-column label="注册时间" align="center" width="150px" prop="register_time" />
        <el-table-column label="操作" align="center" width="90px" fixed="right">
          <template slot-scope="{row}">
            <el-dropdown>
              <el-button type="primary" size="mini">
                操作<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(row)">编 辑</el-dropdown-item>
                <el-dropdown-item @click.native="handleDel( {'ids': row.su_id, 'dept_id': row.dept_id} )">删 除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    </div>
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { staffList, delStaff } from '@/api/organ'
import Organ from './components/organ/organ'
import Dialog from './components/organ/person-dialog'
import page from '@/utils/page'

export default {
  components: { Organ, Dialog },
  extends: page,
  props: {
    reqList: {
      default: staffList,
      type: Function
    },
    reqDel: {
      default: delStaff,
      type: Function
    }
  },
  data() {
    return {
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleEdit(e) {
      this.dialog.title = '编辑信息'
      this.dialog.type = 'edit'
      this.app.dialogParam(this.dialog.edit, ['su_id', 'dept_id', 'pos_id'], e)
      this.$refs['dialog'].visible = true
    },
    handleAdd(e) {
      this.dialog.title = '新增信息'
      this.dialog.type = 'add'
      e = {}
      e.dept_id = this.filter.dept_id
      this.app.dialogParam(this.dialog.edit, ['su_id', 'pos_id', 'dept_id'], e)
      this.$refs['dialog'].visible = true
    },
    selectNode(e) {
      const parent_id = e.parent_id
      this.$set(this.filter, 'parent_id', parent_id)
      if (parent_id === '0') {
        this.$set(this.filter, 'dept_id', e.id)
        this.$set(this.filter, 'pos_id', '')
      } else {
        this.$set(this.filter, 'dept_id', '')
        this.$set(this.filter, 'pos_id', e.id)
      }
      this.getList()
    }
  }
}
</script>
<style scoped>
.page-left{
  width: 216px;
  padding: 2px 10px 0 0;
  bottom: 20px;
  top: 20px;
  overflow: hidden;
  position: absolute;
  overflow-y: auto;
  z-index: 9;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.page-left::-webkit-scrollbar {
  display: none;
}
.page-right{
  padding-left: 216px;
  padding-bottom: 20px;
  width: 100%;
}
</style>
